1. 图像信息获取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 获取图像信息

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(){
Mat img = imread("/home/v/home.png");
if(img.empty()){
cout<<"Error: Could not load image."<<endl;
return -1;
}

imshow("img",img);

cout<<"img row: "<<img.rows<<endl;
cout<<"img col: "<<img.cols<<endl;
cout<<"img ch: "<<img.channels()<<endl;

waitKey(0);
return 0;
}

2. 图像ROI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 获取图像信息

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(){
Mat img = imread("/home/v/home.png");
if(img.empty()){
cout<<"Error: Could not load image."<<endl;
return -1;
}

imshow("img",img);

// 图像信息
cout<<"img row: "<<img.rows<<endl;
cout<<"img col: "<<img.cols<<endl;
cout<<"img ch: "<<img.channels()<<endl;

// 图像roi
Mat imageROI(img, Rect(100,100,200,150));
imshow("imageROI",imageROI);
waitKey(0);
return 0;
}